package com.leyou.order.web;

import com.leyou.order.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.Map;

/**
 * @author 虎哥
 */
@RestController
@RequestMapping("pay")
public class PayController {

    @Autowired
    private OrderService orderService;


    /**
     * 回调通知的处理
     * @param data
     * @return
     */
    @PostMapping(value = "/wxpay/notify", produces = MediaType.APPLICATION_XML_VALUE)
    public ResponseEntity<Map<String,String>> handleNotify(@RequestBody Map<String, String> data){
        orderService.handleNotify(data);

        // 返回结果
        Map<String,String> result = new HashMap<>();
        result.put("return_code", "SUCCESS");
        result.put("return_msg", "OK");
        return ResponseEntity.ok(result);
    }
}
